﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL.Distributor;
using Model.Distributor;
using System.Data;



namespace BLL.Distributor
{
    public class DistributorBLL
    {
        private readonly DistributorDAL dal = new DistributorDAL();



        public List<Model.Route.TravelProductEffTime> GetFloorPrice(string sRouteid,string sDiscountRate,ref string sRouteName)
        {
            List<Model.Route.TravelProductEffTime> modelist = new List<Model.Route.TravelProductEffTime>();


            DataSet ds = dal.GetSalerPrice(sRouteid, sDiscountRate);

            if (ds.Tables[0].Rows.Count>0)
            {
                Model.Route.TravelProductEffTime model;
                for (int n = 0; n < ds.Tables[0].Rows.Count; n++)
                {
                    model = new Model.Route.TravelProductEffTime();
                    if (ds.Tables[0].Rows[n]["trid"] != null && ds.Tables[0].Rows[n]["trid"].ToString() != "")
                    {
                        model.trid = int.Parse(ds.Tables[0].Rows[n]["did"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["adultprice"] != null && ds.Tables[0].Rows[n]["adultprice"].ToString() != "")
                    {
                        model.adultprice = Convert.ToDouble(ds.Tables[0].Rows[n]["adultprice"]);
                    }
                    if (ds.Tables[0].Rows[n]["kidprice"] != null && ds.Tables[0].Rows[n]["kidprice"].ToString() != "")
                    {
                        model.kidprice = Convert.ToDouble(ds.Tables[0].Rows[n]["kidprice"]);
                    }
                    if (ds.Tables[0].Rows[n]["oldprice"] != null && ds.Tables[0].Rows[n]["oldprice"].ToString() != "")
                    {
                        model.oldprice = Convert.ToDouble(ds.Tables[0].Rows[n]["oldprice"]);
                    }
                    if (ds.Tables[0].Rows[n]["product_time"] != null && ds.Tables[0].Rows[n]["product_time"].ToString() != "")
                    {
                        model.product_time = ds.Tables[0].Rows[n]["product_time"].ToString();
                    }
                    modelist.Add(model);
                }
            }

            DataSet ds1 = dal.GetSalerRouteName(sRouteid);
            string strRouteName = "";
            if (ds1.Tables[0].Rows.Count > 0)
            {
                strRouteName = ds1.Tables[0].Rows[0][0].ToString();
                sRouteName = strRouteName;
            }
            else
                sRouteName = "";

            



            return modelist;
        }
        
        
        /// <summary>
        /// 手机端登录用获得数据列表
        /// </summary>
        public List<Model.Distributor.Distributor> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        
        public List<Model.Distributor.Distributor> DataTableToList(DataTable dt)
        {
            List<Model.Distributor.Distributor> modelList = new List<Model.Distributor.Distributor>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.Distributor.Distributor  model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.Distributor.Distributor();
                    if (dt.Rows[n]["did"] != null && dt.Rows[n]["did"].ToString() != "")
                    {
                        model.did = int.Parse(dt.Rows[n]["did"].ToString());
                    }
                    if (dt.Rows[n]["dname"] != null && dt.Rows[n]["dname"].ToString() != "")
                    {
                        model.dname = dt.Rows[n]["dname"].ToString();
                    }
                    if (dt.Rows[n]["discount_rate"] != null && dt.Rows[n]["discount_rate"].ToString() != "")
                    {
                        model.discount_rate = Convert.ToDouble(dt.Rows[n]["discount_rate"]);
                    }
                    if (dt.Rows[n]["loginname"] != null && dt.Rows[n]["loginname"].ToString() != "")
                    {
                        model.loginname = dt.Rows[n]["loginname"].ToString();
                    }
                    if (dt.Rows[n]["status"] != null && dt.Rows[n]["status"].ToString() != "")
                    {
                        model.status = Convert.ToInt32(dt.Rows[n]["status"]);
                    }
                    if (dt.Rows[n]["loginpawwd"] != null && dt.Rows[n]["loginpawwd"].ToString() != "")
                    {
                        model.loginpasswd = dt.Rows[n]["loginpawwd"].ToString();
                    }
                    if (dt.Rows[n]["picurl"] != null && dt.Rows[n]["picurl"].ToString() != "")
                    {
                        model.picurl = dt.Rows[n]["picurl"].ToString();
                    }
                    if (dt.Rows[n]["head"] != null && dt.Rows[n]["head"].ToString() != "")
                    {
                        model.head = dt.Rows[n]["head"].ToString();
                    }
                    if (dt.Rows[n]["license"] != null && dt.Rows[n]["license"].ToString() != "")
                    {
                        model.license = dt.Rows[n]["license"].ToString();
                    }
                    if (dt.Rows[n]["address"] != null && dt.Rows[n]["address"].ToString() != "")
                    {
                        model.address = dt.Rows[n]["address"].ToString();
                    }
                    if (dt.Rows[n]["phone"] != null && dt.Rows[n]["phone"].ToString() != "")
                    {
                        model.phone = dt.Rows[n]["phone"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }
        
        
        
        
        public Model.Distributor.QuerySupplier GetQueryModel(int did)
        {
            return dal.GetQueryModel(did);
        }
        
        public bool AddDistributor(Model.Distributor.Distributor mode)
        {
            return dal.AddDistributor(mode);
        }

        public bool EditDistributor(Model.Distributor.Distributor mode)
        {
            return dal.EditDistributor(mode);
        }

        public bool Delete(string did)
        {
            return dal.Delete(did);
        }

        public int GetPriceRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }


        /// <summary>
        /// 价格分页获取数据列表
        /// </summary>
        public DataSet GetPriceListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetPriceListByPage(strWhere, orderby, startIndex, endIndex);
        }


        public DataSet GetViewListSupplierByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetViewListSupplierByPage(strWhere, orderby, startIndex, endIndex);
        }

        /// <summary>
        /// 分页获取供应商数据列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <param name="orderby"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <returns></returns>

        public DataSet GetRouteListByPage(string strSupplierno,string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetRouteListByPage(strSupplierno, strWhere,orderby, startIndex, endIndex);
        }
        
        
        
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        public Model.Distributor.Distributor GetModel(int did)
        {
            return dal.GetModel(did);
        }
        public bool UpdateQRcodePath(string did, string sPath)
        {
            return dal.UpdateQRcodePath(did, sPath);
        }
    }
}
